<h1>Editar Ordem de Serviço</h1>

<form action="<?=$this->url(array("module"=>"admin","controller"=>"os","action"=>"update"),null,true)?>"  method="post">
	<input type="hidden" name="id_os" value="<?=$this->os['id_os']?>" />
	<input type="hidden" name="id_os" value="<?=$this->os['id_mercadoria']?>" />
	<input type="hidden" name="id_os" value="<?=$this->os['id_frete']?>" />
	<input type="hidden" name="id_os" value="<?=$this->os['id_cliente_r']?>" />
	<input type="hidden" name="id_os" value="<?=$this->os['id_cliente_d']?>" />
	<input type="hidden" name="id_os" value="<?=$this->os['id_cliente_c']?>" />
	<input type="hidden" name="id_os" value="<?=$this->os['id_cliente_c']?>" />
	<input type="hidden" name="id_os" value="<?=$this->os['id_cliente_c']?>" />
	<input type="hidden" name="id_os" value="<?=$this->os['id_cliente_c']?>" />

	<p>
		<label>Status:</label><br>
		<select name="status">
    		<option <?if($this->os['status'] == 1) echo 'selected="selected"';?> value="1">Aberto</option>
    		<option <?if($this->os['status'] == 2) echo 'selected="selected"';?> value="2">Em movimento</option>
    		<option <?if($this->os['status'] == 3) echo 'selected="selected"';?> value="3">Fechado</option>
    	</select>
	</p> 
	<fieldset>
	<legend>Remetente</legend>
    	<p>
    		<select name="id_cliente_r">
    			<option>Selecione uma opção</option>
    			<?foreach($this->cliente AS $key => $cliente):?>
    				<option
    					<?if($this->os['id_cliente_r'] == $cliente['id_cliente']) echo 'selected="selected"';?> 
    					value="<?=$cliente['id_cliente']?>">
    					<?=$cliente['rs_nome']?> 					
    				</option>
    			<?endforeach;?>
    		</select>
    	</p>
	    	
	</fieldset>

	<fieldset>
	<legend>Destinatário</legend>          
	    <p>
	    	<select name="id_cliente_d">
	    		<option>Selecione uma opção</option>
    			<?foreach($this->cliente AS $key => $cliente):?>
    				<option
    					<?if($this->os['id_cliente_d'] == $cliente['id_cliente']) echo 'selected="selected"';?> 
    					value="<?=$cliente['id_cliente']?>">
    					<?=$cliente['rs_nome']?> 					
    				</option>
    			<?endforeach;?>
	    	</select>
	    </p>
	    	
	</fieldset>

	<fieldset>
	<legend>Consignatário</legend>
            
	    <p>
	    	<select name="id_cliente_c">
	    		<option>Selecione uma opção</option> 
	    		<?foreach($this->cliente AS $key => $cliente):?>
    				<option
    					<?if($this->os['id_cliente_c'] == $cliente['id_cliente']) echo 'selected="selected"';?> 
    					value="<?=$cliente['id_cliente']?>">
    					<?=$cliente['rs_nome']?> 					
    				</option>
    			<?endforeach;?>
	    	</select>
	    </p>
	    	
	</fieldset>

	<fieldset>
	<legend>Frete por Conta</legend>
            
	    <p>
			<input <?if($this->os['frete_por_conta'] == 1) echo 'checked="checked"';?> type="radio" name="frete_por_conta" value="1" />Remetente<br/>
			<input <?if($this->os['frete_por_conta'] == 2) echo 'checked="checked"';?> type="radio" name="frete_por_conta" value="2" />Destinat&aacute;rio<br/>
	    	<input <?if($this->os['frete_por_conta'] == 3) echo 'checked="checked"';?> type="radio" name="frete_por_conta" value="3" />Consignat&aacute;rio<br/>
	   		<?if($this->os['frete_por_conta'] == null) echo '<b>Obs:</b> Nenhum campo foi selecionado.';?>
		</p>
	    	
	</fieldset>

	<fieldset>
	<legend>Mercadoria Transportada</legend>	 
	    <div class="left_field">
	    	<p>
 				<label>Natureza</label><br/>
                <input type="text" name="natureza_mer" value="
                	<?
                	foreach($this->mercadoria AS $mercadoria):
			        	if($this->os['id_mercadoria'] == $mercadoria['id_mercadoria'])
                			echo $mercadoria['natureza'];
			          endforeach;
			        ?>
                "/>
            </p>

            <p>
            	<label>Esp&eacute;cie</label><br/>
                <input type="text" name="especie_mer" value="
                	<?foreach($this->mercadoria AS $mercadoria):
			        	if($this->os['id_mercadoria'] == $mercadoria['id_mercadoria'])
                			echo $mercadoria['especie'];
			          endforeach;
			        ?>
                "/>
            </p>

	    	<p>
            	<label>Quantidade</label><br/>
                <input type="text" name="quantidade_mer" value="
                	<?foreach($this->mercadoria AS $mercadoria):
			        	if($this->os['id_mercadoria'] == $mercadoria['id_mercadoria'])
                			echo $mercadoria['quantidade'];
			          endforeach;
			        ?>
                " />
            </p>
	    </div>
	    <div class="right_field">
			<p>
            	<label>N&deg; Nota Fiscal</label><br/>
                <input type="text" name="nfiscal_mer" value="
                	<?foreach($this->mercadoria AS $mercadoria):
			        	if($this->os['id_mercadoria'] == $mercadoria['id_mercadoria'])
                			echo $mercadoria['nfiscal'];
			          endforeach;
			        ?>
                " />
            </p>

            <p>
            	<label>Peso</label><br/>
                <input type="text" name="peso_mer" value="
                	<?foreach($this->mercadoria AS $mercadoria):
			        	if($this->os['id_mercadoria'] == $mercadoria['id_mercadoria'])
                			echo $mercadoria['peso'];
			          endforeach;
			        ?>
                " />
           	</p>

	    	<p>
            	<label>Valor</label><br/>
                <input type="text" name="valor_mer" value="
                	<?foreach($this->mercadoria AS $mercadoria):
			        	if($this->os['id_mercadoria'] == $mercadoria['id_mercadoria'])
                			echo $mercadoria['valor'];
			          endforeach;
			        ?>
                " />
            </p>
	    </div>	
	</fieldset>

	<fieldset>
	<legend>Vincular Ve&iacute;culo e Motorista</legend>
        <div class="left_field">    
        	<p>
		    	<label>Motorista</label><br/>
				<select name="id_motorista">
		  			<option value="volvo">Selecionar Veiculo Existente</option>
		  			<?foreach($this->motorista AS $key => $motorista):?>
	    				<option
	    					<?if($this->os['id_motorista'] == $motorista['id_motorista']) echo 'selected="selected"'?> 
	    					value="<?=$motorista['id_motorista']?>">
	    					<?=$motorista['nome']?>
	    				</option>
	    			<?endforeach;?>
				</select>
		    </p>
		    
		    <p>
		    	<label>Veículo</label><br/>
				<select name="id_veiculo">
		  			<option value="volvo">Selecionar Veiculo Existente</option>
		  			<?foreach($this->veiculo AS $key => $veiculo):?>
	    				<option 
	    					<?if($this->os['id_veiculo'] == $veiculo['id_veiculo']) echo 'selected="selected"'?>
	    					value="<?=$veiculo['id_veiculo']?>">
	    					<?=$veiculo['placa']?> | <?=$veiculo['modelo']?>
	    				</option>
	    			<?endforeach;?>
				</select>
		    </p>
	    </div>	
	    <div class="right_field">
	    	<p>
	    		<label>Carreta</label><br/>
				<select name="id_carreta">
		  			<option value="volvo">Selecionar Veiculo Existente</option>
		  			<?foreach($this->carreta AS $key => $carreta):?>
	    				<option 
	    					<?if($this->os['id_carreta'] == $carreta['id_carreta']) echo 'selected="selected"'?>
	    					value="<?=$carreta['id_carreta']?>">
	    					<?=$carreta['placa']?> | <?=$carreta['modelo']?>
	    				</option>
	    			<?endforeach;?>
				</select>
		    </p>
	    </div>
	</fieldset>

	<fieldset>
	<legend>Composi&ccedil;&atilde;o do Frete</legend>  
	    <div class="left_field">
	    	<p>
				<label>Valor</label><br/>
                <input type="text" name="valor_frete" value="
                	<?foreach($this->frete AS $frete):
			        	if($this->os['id_frete'] == $frete['id_frete'])
                			echo $frete['valor'];
			          endforeach;
			        ?>
                "/>
            </p>

	    	<p>
            	<label>Ped&aacute;gio</label><br/>
                <input type="text" name="pedagio_frete" value="
                	<?foreach($this->frete AS $frete):
			        	if($this->os['id_frete'] == $frete['id_frete'])
                			echo $frete['pedagio'];
			          endforeach;
			        ?>
                "/>
           	</p>
           	
           	<p>
            	<label>Seguro</label><br/>
                <input type="text" name="seguro_frete" value="
                	<?foreach($this->frete AS $frete):
			        	if($this->os['id_frete'] == $frete['id_frete'])
                			echo $frete['seguro'];
			          endforeach;
			        ?>
                "/>
            </p>
	    </div>
	    <div class="right_field">
			<p>
           		<label>Outros</label><br/>
                <input type="text" name="outros_frete" value="
                	<?foreach($this->frete AS $frete):
			        	if($this->os['id_frete'] == $frete['id_frete'])
                			echo $frete['outros'];
			          endforeach;
			        ?>
                "/>
           	</p>

	    	<p>
            	<label>Valor Total</label><br/>
                <input type="text" name="valor_total_frete" value="
                	<?foreach($this->frete AS $frete):
			        	if($this->os['id_frete'] == $frete['id_frete'])
                			echo $frete['valor_total'];
			          endforeach;
			        ?>
                "/>
            </p>
            
            <p>
            	<label>ICMS</label><br/>
                <input type="text" name="icms_frete" value="
                	<?foreach($this->frete AS $frete):
			        	if($this->os['id_frete'] == $frete['id_frete'])
                			echo $frete['icms'];
			          endforeach;
			        ?>
                "/>
            </p><br>
	    </div>

	    <p>
			<label>Observa&ccedil;&otilde;es</label><br/>
			<textarea name="obs_frete">
				<?foreach($this->frete AS $frete):
			    	if($this->os['id_frete'] == $frete['id_frete'])
                		echo $frete['obs'];
			        endforeach;
			    ?>
			</textarea>
	    </p>

	<a href="<?=$this->url(array("module"=>"admin","controller"=>"os"),null,true)?>">
		<div class="cancelar">Cancelar</div>
   	</a>
   	<input type="submit" value="Enviar" class="submit" />
</form>